package com.ruoyi.controller.jpjs.mainmaterial;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.service.SysParameterService;
import com.ruoyi.service.jpjs.PublicService;
import com.ruoyi.service.jpjs.mainmaterial.MainMaterialService;
import com.ruoyi.util.BaseResult;
import com.ruoyi.util.ResultEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


/**
 * @author zeo
 * 主材盘点报表
 */
@Controller
@RequestMapping("/mainMaterial")
public class MainMaterialController extends BaseController {

    @Autowired
    PublicService publicService;

    @Autowired
    MainMaterialService mainMaterialService;

    @Autowired
    SysParameterService sysParameterService;

    private String prefix = "jpjs/mainmaterial";

    @GetMapping()
    public String mainMaterial(ModelMap mmap) {
        mmap.put("userComp", publicService.findUserComp());
        return prefix + "/mainMaterial";
    }

    @RequestMapping("/list")
    @ResponseBody
    public TableDataInfo list(@RequestParam Map map) {
        startPage();
        return getDataTable(mainMaterialService.list(map));
    }

    @GetMapping("/add")
    public String add(ModelMap mmap) {
        mmap.put("userComp", publicService.findUserComp());
        mmap.put("standards", sysParameterService.findNameByType("主材盘点报表单位"));
        return prefix + "/add";
    }

    @RequestMapping("/add")
    @ResponseBody
    public AjaxResult add(@RequestParam Map map){
        return toAjax(mainMaterialService.add(map));
    }

    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        mmap.put("userComp", publicService.findUserComp());
        mmap.put("obj", mainMaterialService.findMainMaterialId(id));
        return prefix + "/edit";
    }

    @RequestMapping("/edit")
    @ResponseBody
    public AjaxResult edit(@RequestParam Map map) {
        return toAjax(mainMaterialService.edit(map));
    }

    @RequestMapping("/findProByCompId")
    @ResponseBody
    public BaseResult findProByCompId(String compId) {
        return BaseResult.build(ResultEnum.SUCCESS, mainMaterialService.findProByCompId(compId));
    }

    @RequestMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids){
        return toAjax(mainMaterialService.remove(ids));
    }

}

